<template>
  <el-drawer
    @close="close"
    :visible.sync="dialogVisible"
    title="心愿审核"
    :size="500"
  >
    <el-row :gutter="10" class="box-card">
      <el-form ref="elForm" :model="formData" size="small" label-width="80px">
        <el-col :span="24">
          <el-form-item label="标题" prop="title">
            <span>{{ formData.title }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="所属社区" prop="community">
            <span>{{ formData.community }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="小区" prop="xiaoqu">
            <span>{{ formData.xiaoqu }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="手机号" prop="mobile">
            <span>{{ formData.mobile }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="详情" prop="detail">
            <span>{{ formData.detail }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="formData.picUrl && formData.picUrl.length">
          <el-form-item label="图片" prop="picUrl">
            <el-image
              v-for="(item, index) in formData.picUrl"
              :key="index"
              style="width: 100px; height: 100px"
              :src="item"
              :preview-src-list="formData.picUrl"
            >
            </el-image>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="formData.videoUrl && formData.videoUrl.length">
          <el-form-item label="视频" prop="picUrl">
            <video :src="formData.videoUrl" width="400" height="400" controls="controls"></video>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
    <div class="footer">
      <el-button @click="handelConfirm(2)">驳回</el-button>
      <el-button type="primary" @click="handelConfirm(1)">通过</el-button>
    </div>
  </el-drawer>
</template>
<script>
import { auditXinYuan } from '@/api/xinyuan'
export default {
  props: [],
  data () {
    return {
      dialogVisible: false,
      formData: {
        title: '', // 心愿标题
        community: '', // 社区名称
        xiaoqu: '', // 小区
        mobile: '', // 手机号
        detail: '', // 心愿内容
        picUrl: '' // 图片
      },
      id: null
    }
  },
  methods: {
    /**
     *
     * @param {*} isEdit 是否编辑
     * @param {*} data 编辑时需要的数据
     */
    async isShow (data) {
      this.dialogVisible = true
      await this.$nextTick()
      const formData = this.formData
      for (const key in formData) {
        formData[key] = data[key]
      }
      formData.picUrl = data.picUrl?.split(',') || []
      this.id = data.id
    },
    close () {
      this.$refs.elForm.resetFields()
      this.dialogVisible = false
    },
    async handelConfirm (status) {
      await auditXinYuan({ id: this.id, status })
      this.$notify.success({
        title: '审核完成'
      })
      this.$emit('update:visible')
      this.close()
    }
  }
}

</script>
<style lang="scss" scoped>
.box-card {
  margin-bottom: 10px;
  padding-right: 20px;
  width: 100%;
  padding-left: 10px;
}
.footer {
  display: flex;
  justify-content: space-around;
  margin-bottom: 40px;
  padding-left: 90px;
  padding-right: 20px;
  .el-button {
    width: 100%;
  }
}
::v-deep .el-image {
  margin-left: 10px
}

</style>
